package com.longrise.android.byjk.plugins.dealsituation.course.video2.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.longrise.android.byjk.R;
import com.longrise.common.utils.AppBaseDialog;

import static com.longrise.common.utils.AppUtil.getString;


/**
 * Created by godliness on 2017/8/29.
 * 课后习题
 */

public class HasqaDialog extends AppBaseDialog implements View.OnClickListener {

    private static final String TAG = "HasqaDialog";

    private TextView mTvTitle;
    private TextView mTvContent;
    private TextView mTvConfirm;
    private TextView mTvCancle;

    private boolean mFinished;

    private OnHasqaListener mOnHasqaListener;

    /**
     * 默认为InPutDialog style
     *
     * @param context
     */
    public HasqaDialog(Context context) {
        super(context, R.style.VideoListDialog);
    }

    public void setFlag(boolean isFinish) {
        this.mFinished = isFinish;
    }

    @Override
    public int getLayoutResourceId(Bundle bundle) {
        return R.layout.dialog_clearcache;
    }

    @Override
    public void init() {
        mTvTitle = (TextView) findViewById(R.id.text_course_title);
        mTvContent = (TextView) findViewById(R.id.text_);
        mTvConfirm = (TextView) findViewById(R.id.text_confirm);
        mTvCancle = (TextView) findViewById(R.id.text_cancle);

        swapContent();
    }

    private void swapContent() {
        if (mTvTitle != null) {
            mTvTitle.setText("提示");
        }
        if (mTvContent != null) {
            mTvContent.setText(mFinished ? getString(R.string.cwidfinish_testhint) : getString(R.string.videofinish_testhint));
        }
        if (mTvCancle != null) {
            mTvCancle.setText(getString(R.string.videofinish_testcancle));
        }
        if (mTvConfirm != null) {
            mTvConfirm.setText(mFinished ? getString(R.string.videofinish_testshow) : getString(R.string.videofinish_testconfrim));
        }
    }

    @Override
    public void regEvent() {
        if (mTvConfirm != null) {
            mTvConfirm.setOnClickListener(this);
        }
        if (mTvCancle != null) {
            mTvCancle.setOnClickListener(this);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.text_confirm:
                if (mOnHasqaListener != null) {
                    mOnHasqaListener.toQa();
                }
                break;

            case R.id.text_cancle:
                dismiss();
                break;

            default:
                break;
        }
    }

    public interface OnHasqaListener {
        void toQa();
    }

    public void setQaListener(OnHasqaListener onHasqaListener) {
        this.mOnHasqaListener = onHasqaListener;
    }
}
